dsh-dev-modes 1.1.0 → 1.1.1

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.
Files changed (3) hide show
  1. package/README.md +20 -0
  2. package/client.js +35 -38
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -18,6 +18,26 @@
18
18
 
19
19
  如果 `~/.dsh/skills/` 里还留着同名副本,运行时会优先使用本包注册的版本;可以删掉副本以免困惑。
20
20
 
21
+ ## 自带开关(1.1.0 起)
22
+
23
+ 本包另外挂载两个**宿主级**插件,所以对**所有** Agent 预设生效(包括内置的 Standard / PTC / Minimal / Creator),不只是本包的三个模式。输入框旁边并排两个按钮:
24
+
25
+ | 按钮 | 作用 | 默认 |
26
+ |---|---|---|
27
+ | 🔒 禁止读其它会话 | 每个会话独立:锁定时禁止读取 `~/.dsh/sessions/` 等其它会话文件 | 锁定 |
28
+ | 🔇 静默运行 | 每个会话独立:启动游戏窗口/编辑器时必须挪到屏幕外或改用无窗口方式,不挡前台、不抢焦点 | 静默 |
29
+
30
+ 点一下切换,对**当前会话**生效,下一次模型请求立刻起作用。
31
+
32
+ 状态存储(升级后原有设置保留):
33
+
34
+ ```
35
+ $DSH_HOME/storages/dsh-session-lock/policies.json
36
+ $DSH_HOME/storages/dsh-quiet-run/state.json
37
+ ```
38
+
39
+ > 这两个是**提示词级约束**,不是强制拦截:模型被告知规则并遵守,但宿主不会物理阻止。窗口挪出屏幕后仍占用 GPU/CPU。
40
+
21
41
  ## 安装
22
42
 
23
43
  ```text
package/client.js CHANGED
@@ -44,20 +44,30 @@ window.__ModuleLoader__.load({
44
44
  return await res.json();
45
45
  }
46
46
 
47
- /** 通用开关按钮:读一次状态,之后每 5 秒刷新。 */
48
- function useSwitch(apiPath, key, fallback) {
49
- const [value, setValue] = React.useState(fallback);
47
+ function stateUrl(apiPath, sessionId) {
48
+ return apiPath + '/state' + (sessionId ? '?sessionId=' + encodeURIComponent(sessionId) : '');
49
+ }
50
+
51
+ /**
52
+ * 一个开关按钮。
53
+ * sessionId 来自插槽标准 props —— 必须带上,否则宿主只能猜"当前会话",
54
+ * 多开窗口时会写到别的会话去(表现就是"点了没反应 / 关不掉")。
55
+ */
56
+ function SwitchButton({ apiPath, sessionId, swKey, iconOn, iconOff, labelOn, labelOff, titleOn, titleOff }) {
57
+ const [value, setValue] = React.useState(true);
50
58
  const [ready, setReady] = React.useState(false);
59
+ const [busy, setBusy] = React.useState(false);
60
+ const [note, setNote] = React.useState('');
51
61
 
52
62
  const refresh = React.useCallback(async () => {
53
63
  try {
54
- const s = await getJson(apiPath + '/state');
64
+ const s = await getJson(stateUrl(apiPath, sessionId));
55
65
  setReady(Boolean(s.ready));
56
- setValue(s[key] !== false);
66
+ setValue(s[swKey] !== false);
57
67
  } catch (e) {
58
68
  setReady(false);
59
69
  }
60
- }, [apiPath, key]);
70
+ }, [apiPath, sessionId, swKey]);
61
71
 
62
72
  React.useEffect(() => {
63
73
  refresh();
@@ -65,34 +75,20 @@ window.__ModuleLoader__.load({
65
75
  return () => clearInterval(id);
66
76
  }, [refresh]);
67
77
 
68
- const set = React.useCallback(
69
- async (next) => {
70
- await postJson(apiPath + '/set', { [key]: next });
71
- setValue(next);
72
- },
73
- [apiPath, key],
74
- );
75
-
76
- return { value, ready, set };
77
- }
78
-
79
- function SwitchButton({ apiPath, key, iconOn, iconOff, labelOn, labelOff, titleOn, titleOff, warnWhenOn }) {
80
- const { value, ready, set } = useSwitch(apiPath, key, key !== 'locked');
81
- const [busy, setBusy] = React.useState(false);
82
- const [note, setNote] = React.useState('');
83
-
84
78
  const onClick = async () => {
85
79
  if (busy || !ready) return;
86
80
  setBusy(true);
87
81
  setNote('');
82
+ const next = !value;
88
83
  try {
89
- const next = !value;
90
- await set(next);
84
+ await postJson(apiPath + '/set', { sessionId, [swKey]: next });
85
+ setValue(next);
91
86
  setNote(next ? '已开启' : '已关闭');
92
87
  setTimeout(() => setNote(''), 3000);
88
+ setTimeout(refresh, 300);
93
89
  } catch (e) {
94
90
  setNote('切换失败:' + ((e && e.message) || String(e)));
95
- setTimeout(() => setNote(''), 5000);
91
+ setTimeout(() => setNote(''), 6000);
96
92
  } finally {
97
93
  setBusy(false);
98
94
  }
@@ -100,8 +96,13 @@ window.__ModuleLoader__.load({
100
96
 
101
97
  const icon = !ready ? '⏳' : value ? iconOn : iconOff;
102
98
  const label = !ready ? '未就绪' : value ? labelOn : labelOff;
103
- const title = !ready ? '本会话尚未建立,稍后再试' : value ? titleOn : titleOff;
104
- const warn = ready && warnWhenOn ? value : false;
99
+ const title = !ready
100
+ ? sessionId
101
+ ? '本会话尚未建立,稍后再试'
102
+ : '还没有会话,稍后再试'
103
+ : value
104
+ ? titleOn
105
+ : titleOff;
105
106
 
106
107
  return h(
107
108
  'div',
@@ -113,12 +114,7 @@ window.__ModuleLoader__.load({
113
114
  onClick,
114
115
  disabled: busy || !ready,
115
116
  title,
116
- style: Object.assign(
117
- {},
118
- baseBtn,
119
- busy || !ready ? { opacity: 0.55 } : null,
120
- warn ? { borderColor: 'rgba(255,138,0,0.6)' } : null,
121
- ),
117
+ style: Object.assign({}, baseBtn, busy || !ready ? { opacity: 0.55 } : null),
122
118
  },
123
119
  h('span', { style: { fontSize: 14 } }, icon),
124
120
  h('span', { style: { fontSize: 12, opacity: 0.85 } }, label),
@@ -127,31 +123,32 @@ window.__ModuleLoader__.load({
127
123
  );
128
124
  }
129
125
 
130
- function DevModeSwitch() {
126
+ function DevModeSwitch(props) {
127
+ const sessionId = props && props.sessionId;
131
128
  return h(
132
129
  'div',
133
130
  { style: { display: 'inline-flex', alignItems: 'center', gap: 8 } },
134
131
  h(SwitchButton, {
135
132
  apiPath: '/dsh-session-lock',
136
- key: 'locked',
133
+ sessionId,
134
+ swKey: 'locked',
137
135
  iconOn: '🔒',
138
136
  iconOff: '🔓',
139
137
  labelOn: '禁止读其它会话',
140
138
  labelOff: '允许读其它会话',
141
139
  titleOn: '当前会话已锁定:不会读取其它会话的内容。点击允许。',
142
140
  titleOff: '当前会话已允许:可以读取其它会话。点击锁定。',
143
- warnWhenOn: false,
144
141
  }),
145
142
  h(SwitchButton, {
146
143
  apiPath: '/dsh-quiet-run',
147
- key: 'quiet',
144
+ sessionId,
145
+ swKey: 'quiet',
148
146
  iconOn: '🔇',
149
147
  iconOff: '🔊',
150
148
  labelOn: '静默运行',
151
149
  labelOff: '可见运行',
152
150
  titleOn: '静默运行:启动游戏或编辑器时会挪到屏幕外,不挡你、不抢焦点。点击改为可见。',
153
151
  titleOff: '可见运行:允许窗口出现在前台。点击改回静默。',
154
- warnWhenOn: false,
155
152
  }),
156
153
  );
157
154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-dev-modes",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "description": "Three DeepSeek Harness Agent presets in one bundle — plus the per-session isolation and quiet-run switches: software development, game development, and read-only discussion, with the matching delivery and engine workflows bundled as skills.",
6
6
  "author": "qingfengshangnanzhi",