dsh-completion-traffic-light 0.0.0-stage → 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 completion-traffic-light contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,73 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # 任务完成红绿灯 · Completion traffic light
2
+
3
+ 一个 DSH 插件:用红黄绿灯告诉你当前任务处于什么状态。灯有两处显示:
4
+
5
+ - **客户端窗口内**:输入框下方状态带里的一枚小灯(所有平台)
6
+ - **客户端窗口外**:桌面右下角的置顶小窗(仅 Windows 桌面端)
7
+
8
+ | 运行中 | 等待你处理 | 已完成 |
9
+ | --- | --- | --- |
10
+ | ![运行中](assets/floating-running.png) | ![等待你处理](assets/floating-waiting.png) | ![已完成](assets/floating-done.png) |
11
+
12
+ ## 灯的含义
13
+
14
+ | 灯 | 状态 | 含义 |
15
+ | --- | --- | --- |
16
+ | 🔴 红 | 运行中 | 至少有一个会话正在跑 turn(子代理也算) |
17
+ | 🟡 黄 | 等待你处理 | 有审批或提问在等你 |
18
+ | 🟢 绿 | 已完成 | 所有 turn 结束;刚结束时绿灯会额外亮 8 秒 |
19
+ | ⚪ 灰 | 待命 | 本次启动还没有跑过任务 |
20
+
21
+ ## 安装
22
+
23
+ ```sh
24
+ dsh plugin add dsh-completion-traffic-light
25
+ ```
26
+
27
+ 装完重启 DeepSeek Harness 即可看到输入框下方的灯;Windows 桌面端还会在右下角出现置顶小窗。
28
+
29
+ 也可以从 GitHub 安装:
30
+
31
+ ```sh
32
+ dsh plugin add github:LuckYur/completion-traffic-light
33
+ ```
34
+
35
+ ## 窗外小窗(Windows 桌面端)
36
+
37
+ - 默认贴在屏幕**右下角**,始终置顶
38
+ - **空闲自动贴边收起**:没有任务在跑时,窗口收成一条 14px 宽的小指示条贴在右边(只显示一个状态点);鼠标移上去展开,移开且仍空闲 2.5 秒后再收起来;任务一开始跑就自动展开
39
+ - **拖动**:按住左键拖动
40
+ - **透明度**:脚本顶部的 `$windowOpacity`(`1.0` 完全不透明,`0.85` 略透出背景,越小越透)
41
+ - **双击 / 右键「回到 DeepSeek Harness」**:把主窗口叫回前台
42
+ - **右键「关闭红绿灯」**:关掉小窗;异常退出时 Host 会在 3 秒后自动拉起(最多 5 次)
43
+ - 宿主进程退出时小窗会自行关闭,不会留下孤儿窗口
44
+
45
+ ## 配置
46
+
47
+ 在 profile 的 patch 层把该行的 config 设为 `window: false` 可关闭窗外小窗,只保留窗口内的灯:
48
+
49
+ ```yaml
50
+ - id: completion-traffic-light
51
+ name: 'dsh-completion-traffic-light'
52
+ config:
53
+ window: false
54
+ ```
55
+
56
+ ## 结构
57
+
58
+ | 文件 | 作用 |
59
+ | --- | --- |
60
+ | `index.js` | Host 半:监听 `api-session/status`,把聚合状态写进状态文件,并拉起/回收小窗进程 |
61
+ | `float-window.ps1` | 小窗本体:PowerShell + WinForms,轮询状态文件绘制三灯 |
62
+ | `client.js` | Client 半:注册到 `conversation.composer.dock`,用 `useSessionStatus` 画窗口内的灯 |
63
+ | `cordis.patch.yml` | bundle 的插入行 |
64
+ | `locale/*.json` | 插件管理里的标题/描述与灯的中英文文案 |
65
+
66
+ 小窗通过临时目录里的 `state.txt` 和 Host 通信(`running` / `waiting` / `done:<epoch-ms>` / `idle`),Host 退出时小窗检测不到父进程会自行退出。
67
+
68
+ > 改 `float-window.ps1` 时必须保存为 **UTF-8 with BOM**:Windows PowerShell 5.1 会把无 BOM 的 UTF-8 当 GBK 解码,中文乱码后整个脚本解析失败、窗口起不来。
69
+
70
+ ## 已知限制
71
+
72
+ - 窗外小窗只在 **Windows 桌面端**启动;web 版只有窗口内的灯。
73
+ - 小窗位置不记忆,重启回到右下角。
Binary file
Binary file
Binary file
package/client.js ADDED
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Browser half of the completion traffic light.
3
+ *
4
+ * The light sits in `conversation.composer.dock`, directly under the composer,
5
+ * and reads the session's unified UI status through the standard
6
+ * `useSessionStatus` seat:
7
+ *
8
+ * red — the agent is working on the current turn
9
+ * amber — a turn finished but something still waits for the user
10
+ * green — the turn is finished and nothing is pending
11
+ *
12
+ * A green light glows harder for a few seconds right after a turn ends, so the
13
+ * completion is noticeable without watching the transcript.
14
+ */
15
+ window.__ModuleLoader__.load({
16
+ id: 'dsh-completion-traffic-light',
17
+ factory(require) {
18
+ const React = require('react')
19
+ const h = React.createElement
20
+
21
+ const NS = 'completion-traffic-light'
22
+ const RED = '#ff4d4f'
23
+ const AMBER = '#ffb020'
24
+ const GREEN = '#22c55e'
25
+ const GLOW_MS = 8000
26
+
27
+ /** One lamp of the traffic light; inactive lamps stay visible but dim. */
28
+ function lamp(color, active, bright) {
29
+ return h('span', {
30
+ 'aria-hidden': true,
31
+ style: {
32
+ width: 8,
33
+ height: 8,
34
+ borderRadius: '50%',
35
+ background: color,
36
+ opacity: active ? 1 : 0.16,
37
+ boxShadow: active
38
+ ? (bright ? `0 0 9px 2px ${color}` : `0 0 4px 0 ${color}`)
39
+ : 'none',
40
+ transition: 'opacity 160ms ease, box-shadow 240ms ease',
41
+ },
42
+ })
43
+ }
44
+
45
+ /**
46
+ * Build the slot component bound to one translate function.
47
+ * @param t - namespace-bound translate function.
48
+ * @returns the traffic light component.
49
+ */
50
+ function createTrafficLight(t) {
51
+ return function TrafficLight(props) {
52
+ const { sessionId, useSessionStatus } = props
53
+ const status = useSessionStatus(snapshot => snapshot.get(sessionId))
54
+ const running = status === undefined ? undefined : status.running
55
+ // A question or approval prompt keeps the turn running, so the pending
56
+ // interaction outranks the running lamp instead of waiting for it to end.
57
+ const waiting = status !== undefined && status.pendingInteraction !== undefined
58
+ const done = !waiting && running === false
59
+
60
+ const [justCompleted, setJustCompleted] = React.useState(false)
61
+ const previousRunning = React.useRef(running)
62
+ React.useEffect(() => {
63
+ const was = previousRunning.current
64
+ previousRunning.current = running
65
+ if (was !== true || running !== false) return undefined
66
+ setJustCompleted(true)
67
+ const timer = setTimeout(() => setJustCompleted(false), GLOW_MS)
68
+ return () => clearTimeout(timer)
69
+ }, [running])
70
+
71
+ const state = waiting ? 'waiting' : running === true ? 'running' : done ? 'done' : 'idle'
72
+ const label = t(state)
73
+ const description = t('aria', { state: label })
74
+
75
+ return h('div', {
76
+ role: 'status',
77
+ 'aria-label': description,
78
+ title: description,
79
+ style: {
80
+ display: 'inline-flex',
81
+ alignItems: 'center',
82
+ gap: 6,
83
+ padding: '3px 9px 3px 8px',
84
+ borderRadius: 999,
85
+ background: 'var(--dsw-alias-bg-layer-2)',
86
+ border: '1px solid var(--dsw-alias-border-l1)',
87
+ color: 'var(--dsw-alias-label-secondary)',
88
+ fontSize: 11,
89
+ lineHeight: '14px',
90
+ userSelect: 'none',
91
+ },
92
+ },
93
+ h('span', { 'aria-hidden': true, style: { display: 'inline-flex', gap: 3 } },
94
+ lamp(RED, state === 'running', false),
95
+ lamp(AMBER, state === 'waiting', false),
96
+ lamp(GREEN, state === 'done', justCompleted),
97
+ ),
98
+ h('span', { style: { whiteSpace: 'nowrap' } }, label),
99
+ )
100
+ }
101
+ }
102
+
103
+ return {
104
+ inject: ['slots', 'locale'],
105
+ apply(ctx) {
106
+ const t = ctx.locale.bind(NS)
107
+ ctx.effect(() => ctx.locale.register(NS, {
108
+ zh: {
109
+ running: '运行中',
110
+ waiting: '等待你处理',
111
+ done: '已完成',
112
+ idle: '待命',
113
+ aria: '任务状态:{state}',
114
+ },
115
+ en: {
116
+ running: 'Working',
117
+ waiting: 'Needs you',
118
+ done: 'Done',
119
+ idle: 'Idle',
120
+ aria: 'Task status: {state}',
121
+ },
122
+ }), 'completion-traffic-light: dictionaries')
123
+ const TrafficLight = createTrafficLight(t)
124
+ ctx.slots.inject('conversation.composer.dock', () => ctx.slots.register({
125
+ name: 'conversation.composer.dock',
126
+ id: 'completion-traffic-light',
127
+ order: 5,
128
+ }, TrafficLight))
129
+ },
130
+ }
131
+ },
132
+ })
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: completion-traffic-light
3
+ name: 'dsh-completion-traffic-light'
@@ -0,0 +1,294 @@
1
+ param(
2
+ [Parameter(Mandatory = $true)][string]$StateFile,
3
+ [int]$ParentPid = 0
4
+ )
5
+
6
+ Add-Type -AssemblyName System.Windows.Forms
7
+ Add-Type -AssemblyName System.Drawing
8
+
9
+ Add-Type -TypeDefinition @"
10
+ using System;
11
+ using System.Runtime.InteropServices;
12
+ public class DshActivate {
13
+ [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd);
14
+ [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
15
+ }
16
+ "@
17
+
18
+ # 窗口不透明度:1.0 = 完全不透明,0.85 = 略透出背景。改这一行即可。
19
+ $windowOpacity = 0.85
20
+ # 展开宽度 / 贴边收起后的宽度 / 高度
21
+ $expandedWidth = 158
22
+ $collapsedWidth = 14
23
+ $windowHeight = 42
24
+ # 空闲多久后自动贴边收起(毫秒)
25
+ $idleCollapseDelay = 2500
26
+
27
+ # 状态文件内容:running | waiting | done | idle;done 可带 ":<epoch-ms>" 标记刚完成
28
+ function Read-State {
29
+ try {
30
+ if (-not (Test-Path -LiteralPath $StateFile)) { return @{ state = 'idle'; at = 0 } }
31
+ $text = (Get-Content -LiteralPath $StateFile -Raw -ErrorAction Stop).Trim()
32
+ if ($text.Length -eq 0) { return @{ state = 'idle'; at = 0 } }
33
+ $parts = $text.Split(':')
34
+ $state = $parts[0]
35
+ $at = 0
36
+ if ($parts.Length -gt 1) { [void][long]::TryParse($parts[1], [ref]$at) }
37
+ return @{ state = $state; at = $at }
38
+ } catch {
39
+ return @{ state = 'idle'; at = 0 }
40
+ }
41
+ }
42
+
43
+ # 双击或菜单回到 DeepSeek Harness 主窗口
44
+ function Activate-App {
45
+ try {
46
+ $app = Get-Process -Name 'DeepSeek Harness' -ErrorAction SilentlyContinue |
47
+ Where-Object { $_.MainWindowHandle -ne 0 } |
48
+ Select-Object -First 1
49
+ if ($null -eq $app) { return }
50
+ [void][DshActivate]::ShowWindow($app.MainWindowHandle, 9)
51
+ [void][DshActivate]::SetForegroundWindow($app.MainWindowHandle)
52
+ } catch {
53
+ }
54
+ }
55
+
56
+ $script:current = 'idle'
57
+ $script:flashUntil = 0
58
+ $script:dragging = $false
59
+ $script:dragX = 0
60
+ $script:dragY = 0
61
+ $script:ticks = 0
62
+ $script:lastVisual = ''
63
+ $script:collapsed = $false
64
+ $script:hover = $false
65
+ $script:idleSince = 0
66
+
67
+ $red = [System.Drawing.Color]::FromArgb(255, 77, 79)
68
+ $amber = [System.Drawing.Color]::FromArgb(255, 176, 32)
69
+ $green = [System.Drawing.Color]::FromArgb(34, 197, 94)
70
+ $idleColor = [System.Drawing.Color]::FromArgb(122, 128, 144)
71
+ $back = [System.Drawing.Color]::FromArgb(31, 36, 48)
72
+ $textColor = [System.Drawing.Color]::FromArgb(232, 232, 236, 244)
73
+
74
+ $form = New-Object System.Windows.Forms.Form
75
+ $form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::None
76
+ $form.StartPosition = [System.Windows.Forms.FormStartPosition]::Manual
77
+ $form.TopMost = $true
78
+ $form.ShowInTaskbar = $false
79
+ $form.Width = $expandedWidth
80
+ $form.Height = $windowHeight
81
+ $form.BackColor = $back
82
+ $form.Opacity = $windowOpacity
83
+
84
+ $area = [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea
85
+ $form.Left = $area.Right - $expandedWidth
86
+ $form.Top = $area.Bottom - $windowHeight - 24
87
+
88
+ $picture = New-Object System.Windows.Forms.PictureBox
89
+ $picture.Dock = [System.Windows.Forms.DockStyle]::Fill
90
+ $picture.BackColor = $back
91
+ $picture.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::Normal
92
+ $form.Controls.Add($picture)
93
+
94
+ # 圆角外形随窗口尺寸重建(展开时是胶囊,收起时是贴边的窄条)
95
+ function Update-Region {
96
+ $w = $form.Width
97
+ $h = $form.Height
98
+ $r = [Math]::Min(14, [Math]::Min([int]($w / 2), [int]($h / 2)))
99
+ if ($r -lt 2) { $r = 2 }
100
+ $path = New-Object System.Drawing.Drawing2D.GraphicsPath
101
+ $path.AddArc(0, 0, $r, $r, 180, 90)
102
+ $path.AddArc($w - $r, 0, $r, $r, 270, 90)
103
+ $path.AddArc($w - $r, $h - $r, $r, $r, 0, 90)
104
+ $path.AddArc(0, $h - $r, $r, $r, 90, 90)
105
+ $path.CloseFigure()
106
+ $form.Region = New-Object System.Drawing.Region($path)
107
+ $path.Dispose()
108
+ }
109
+ Update-Region
110
+
111
+ function State-Color {
112
+ param([string]$state)
113
+ switch ($state) {
114
+ 'running' { return $red }
115
+ 'waiting' { return $amber }
116
+ 'done' { return $green }
117
+ default { return $idleColor }
118
+ }
119
+ }
120
+
121
+ function New-LightImage {
122
+ $w = $form.ClientSize.Width
123
+ $h = $form.ClientSize.Height
124
+ $bmp = New-Object System.Drawing.Bitmap($w, $h)
125
+ $g = [System.Drawing.Graphics]::FromImage($bmp)
126
+ $g.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
127
+ $g.TextRenderingHint = [System.Drawing.Text.TextRenderingHint]::ClearTypeGridFit
128
+
129
+ $bg = New-Object System.Drawing.SolidBrush($back)
130
+ $g.FillRectangle($bg, 0, 0, $w, $h)
131
+ $bg.Dispose()
132
+
133
+ $state = $script:current
134
+ $justDone = ([DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() -lt $script:flashUntil)
135
+
136
+ if ($script:collapsed) {
137
+ # 贴边收起:只留一个状态灯
138
+ $size = 8
139
+ $x = [int](($w - $size) / 2)
140
+ $y = [int](($h - $size) / 2)
141
+ $color = State-Color $state
142
+ if ($state -eq 'done' -and $justDone) {
143
+ $glow = New-Object System.Drawing.SolidBrush([System.Drawing.Color]::FromArgb(90, $color))
144
+ $g.FillEllipse($glow, $x - 4, $y - 4, $size + 8, $size + 8)
145
+ $glow.Dispose()
146
+ }
147
+ $brush = New-Object System.Drawing.SolidBrush($color)
148
+ $g.FillEllipse($brush, $x, $y, $size, $size)
149
+ $brush.Dispose()
150
+ } else {
151
+ $lights = @(
152
+ @{ X = 16; Color = $red; Active = ($state -eq 'running') },
153
+ @{ X = 38; Color = $amber; Active = ($state -eq 'waiting') },
154
+ @{ X = 60; Color = $green; Active = ($state -eq 'done') }
155
+ )
156
+ foreach ($light in $lights) {
157
+ if ($light.Active) {
158
+ if ($state -eq 'done' -and $justDone) {
159
+ $glow = New-Object System.Drawing.SolidBrush([System.Drawing.Color]::FromArgb(72, $light.Color))
160
+ $g.FillEllipse($glow, $light.X - 4, 11, 20, 20)
161
+ $glow.Dispose()
162
+ }
163
+ $brush = New-Object System.Drawing.SolidBrush($light.Color)
164
+ $g.FillEllipse($brush, $light.X, 15, 12, 12)
165
+ $brush.Dispose()
166
+ } else {
167
+ $dim = New-Object System.Drawing.SolidBrush([System.Drawing.Color]::FromArgb(46, $light.Color))
168
+ $g.FillEllipse($dim, $light.X, 15, 12, 12)
169
+ $dim.Dispose()
170
+ }
171
+ }
172
+
173
+ $label = switch ($state) {
174
+ 'running' { '运行中' }
175
+ 'waiting' { '等待你处理' }
176
+ 'done' { '已完成' }
177
+ default { '待命' }
178
+ }
179
+
180
+ $font = New-Object System.Drawing.Font('Microsoft YaHei UI', 9)
181
+ $textBrush = New-Object System.Drawing.SolidBrush($textColor)
182
+ $g.DrawString($label, $font, $textBrush, 82, 13)
183
+ $textBrush.Dispose()
184
+ $font.Dispose()
185
+ }
186
+
187
+ $g.Dispose()
188
+ return $bmp
189
+ }
190
+
191
+ function Update-Visual {
192
+ $justDone = ([DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() -lt $script:flashUntil)
193
+ $visual = "$($script:current)|$justDone|$($script:collapsed)"
194
+ if ($visual -eq $script:lastVisual) { return }
195
+ $script:lastVisual = $visual
196
+ $old = $picture.Image
197
+ $picture.Image = New-LightImage
198
+ if ($null -ne $old) { $old.Dispose() }
199
+ }
200
+
201
+ # 收起 / 展开:右边缘始终贴着屏幕右边
202
+ function Set-Collapsed {
203
+ param([bool]$collapsed)
204
+ if ($script:collapsed -eq $collapsed) { return }
205
+ $script:collapsed = $collapsed
206
+ $screen = [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea
207
+ $width = if ($collapsed) { $collapsedWidth } else { $expandedWidth }
208
+ $top = $form.Top
209
+ if ($top -lt $screen.Top) { $top = $screen.Top }
210
+ if (($top + $windowHeight) -gt $screen.Bottom) { $top = $screen.Bottom - $windowHeight }
211
+ $form.SetBounds($screen.Right - $width, $top, $width, $windowHeight)
212
+ Update-Region
213
+ $script:lastVisual = ''
214
+ Update-Visual
215
+ }
216
+
217
+ # 拖动/双击/右键都挂在铺满窗口的 PictureBox 上:它盖住了 Form,Form 自己收不到鼠标事件
218
+ $picture.Add_MouseDown({
219
+ param($sender, $e)
220
+ if ($e.Button -eq [System.Windows.Forms.MouseButtons]::Left) {
221
+ $script:dragging = $true
222
+ $script:dragX = $e.X
223
+ $script:dragY = $e.Y
224
+ }
225
+ })
226
+ $picture.Add_MouseMove({
227
+ param($sender, $e)
228
+ if ($script:dragging) {
229
+ $form.Left = $form.Left + ($e.X - $script:dragX)
230
+ $form.Top = $form.Top + ($e.Y - $script:dragY)
231
+ }
232
+ })
233
+ $picture.Add_MouseUp({
234
+ param($sender, $e)
235
+ $script:dragging = $false
236
+ })
237
+ $picture.Add_MouseEnter({
238
+ $script:hover = $true
239
+ if ($script:collapsed) { Set-Collapsed $false }
240
+ })
241
+ $picture.Add_MouseLeave({
242
+ $script:hover = $false
243
+ })
244
+ $picture.Add_DoubleClick({ Activate-App })
245
+
246
+ $menu = New-Object System.Windows.Forms.ContextMenuStrip
247
+ $openItem = $menu.Items.Add('回到 DeepSeek Harness')
248
+ $openItem.Add_Click({ Activate-App })
249
+ [void]$menu.Items.Add('-')
250
+ $closeItem = $menu.Items.Add('关闭红绿灯')
251
+ $closeItem.Add_Click({ $form.Close() })
252
+ $picture.ContextMenuStrip = $menu
253
+ $form.ContextMenuStrip = $menu
254
+
255
+ $timer = New-Object System.Windows.Forms.Timer
256
+ $timer.Interval = 400
257
+ $timer.Add_Tick({
258
+ $script:ticks = $script:ticks + 1
259
+
260
+ # 宿主进程消失后自行退出,避免留下孤儿窗口
261
+ if ($ParentPid -gt 0 -and ($script:ticks % 12) -eq 0) {
262
+ $alive = Get-Process -Id $ParentPid -ErrorAction SilentlyContinue
263
+ if ($null -eq $alive) { $form.Close(); return }
264
+ }
265
+
266
+ $next = Read-State
267
+ if ($next.state -ne $script:current) { $script:current = $next.state }
268
+ if ($next.state -eq 'done' -and $next.at -gt 0 -and ($next.at + 8000) -gt $script:flashUntil) {
269
+ $script:flashUntil = $next.at + 8000
270
+ }
271
+
272
+ $now = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()
273
+ $busy = ($script:current -eq 'running') -or ($script:current -eq 'waiting')
274
+ if ($busy) {
275
+ $script:idleSince = 0
276
+ Set-Collapsed $false
277
+ } else {
278
+ if ($script:idleSince -eq 0) { $script:idleSince = $now }
279
+ if (-not $script:hover -and -not $script:collapsed -and ($now - $script:idleSince) -gt $idleCollapseDelay) {
280
+ Set-Collapsed $true
281
+ }
282
+ }
283
+
284
+ Update-Visual
285
+ })
286
+ $timer.Start()
287
+
288
+ $form.Add_Shown({
289
+ Update-Region
290
+ Update-Visual
291
+ })
292
+ $form.Add_FormClosed({ $timer.Stop() })
293
+
294
+ [void][System.Windows.Forms.Application]::Run($form)
package/icon.svg ADDED
@@ -0,0 +1,8 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="Traffic light">
2
+ <rect x="18" y="5" width="28" height="50" rx="10" fill="#1f2430"/>
3
+ <rect x="21.5" y="8.5" width="21" height="43" rx="7.5" fill="#2b3242"/>
4
+ <circle cx="32" cy="18" r="5.5" fill="#ff4d4f" opacity="0.3"/>
5
+ <circle cx="32" cy="30" r="5.5" fill="#ffb020" opacity="0.3"/>
6
+ <circle cx="32" cy="42" r="5.5" fill="#22c55e"/>
7
+ <rect x="28" y="56" width="8" height="5" rx="2.5" fill="#1f2430"/>
8
+ </svg>
package/index.js ADDED
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Host half of the completion traffic light.
3
+ *
4
+ * On the Desktop build it owns a small always-on-top window that sits outside
5
+ * the application window and mirrors the aggregate turn state:
6
+ *
7
+ * red — at least one Session is running a turn
8
+ * green — every turn finished (the light glows for a few seconds on the transition)
9
+ * idle — nothing has run in this process yet
10
+ *
11
+ * The window is a PowerShell WinForms process; this plugin only publishes the
12
+ * state to a file it polls, and kills it when the plugin is disposed or the
13
+ * Host exits.
14
+ */
15
+ import { spawn } from 'node:child_process'
16
+ import { mkdtempSync, writeFileSync } from 'node:fs'
17
+ import { tmpdir } from 'node:os'
18
+ import { join } from 'node:path'
19
+ import { fileURLToPath } from 'node:url'
20
+
21
+ const WINDOW_SCRIPT = fileURLToPath(new URL('./float-window.ps1', import.meta.url))
22
+
23
+ /** Electron's Node mode marks the Desktop host; other profiles render in-page only. */
24
+ function isDesktopHost() {
25
+ return process.platform === 'win32' && process.env.ELECTRON_RUN_AS_NODE === '1'
26
+ }
27
+
28
+ /**
29
+ * Start the floating window and keep its state file in step with live turns.
30
+ * @param ctx - the plugin context owning the window lifetime.
31
+ * @param config - optional row config; `window: false` disables the floating window.
32
+ */
33
+ export function apply(ctx, config) {
34
+ if (!isDesktopHost()) return
35
+ if (config !== undefined && config !== null && config.window === false) return
36
+
37
+ const stateFile = join(mkdtempSync(join(tmpdir(), 'dsh-traffic-light-')), 'state.txt')
38
+ let last = 'idle'
39
+ let ready = true
40
+ function publish(state) {
41
+ if (state === last || !ready) return
42
+ last = state
43
+ try {
44
+ writeFileSync(stateFile, state === 'done' ? `done:${Date.now()}` : state)
45
+ } catch (error) {
46
+ console.warn('completion-traffic-light: could not publish state', error)
47
+ }
48
+ }
49
+ writeFileSync(stateFile, 'idle')
50
+
51
+ let child
52
+ let disposed = false
53
+ let restarts = 0
54
+ let restartTimer
55
+ function startWindow() {
56
+ ready = true
57
+ try {
58
+ child = spawn('powershell.exe', [
59
+ '-NoProfile',
60
+ '-ExecutionPolicy', 'Bypass',
61
+ '-WindowStyle', 'Hidden',
62
+ '-File', WINDOW_SCRIPT,
63
+ '-StateFile', stateFile,
64
+ '-ParentPid', String(process.pid),
65
+ ], { windowsHide: true, stdio: 'ignore' })
66
+ } catch (error) {
67
+ console.warn('completion-traffic-light: could not open the floating window', error)
68
+ ready = false
69
+ return
70
+ }
71
+ child.on('error', error => {
72
+ console.warn('completion-traffic-light: floating window failed', error)
73
+ ready = false
74
+ })
75
+ child.on('exit', code => {
76
+ if (disposed) return
77
+ // The "关闭红绿灯" menu exits cleanly; a crash or an outside kill is
78
+ // retried so the indicator cannot disappear without a way back.
79
+ if (code === 0) return
80
+ if (restarts >= 5) {
81
+ console.warn('completion-traffic-light: floating window keeps exiting; giving up')
82
+ return
83
+ }
84
+ restarts += 1
85
+ restartTimer = setTimeout(startWindow, 3000)
86
+ })
87
+ }
88
+ startWindow()
89
+ ctx.effect(() => () => {
90
+ disposed = true
91
+ clearTimeout(restartTimer)
92
+ try { child?.kill() } catch { /* the window already exited */ }
93
+ })
94
+
95
+ const active = new Set()
96
+ let started = false
97
+ /**
98
+ * Whether any client still waits for an answer (AskUserQuestion or approval).
99
+ * The turn keeps running meanwhile, so this outranks the running state.
100
+ * @returns true while a pending remote request is unanswered.
101
+ */
102
+ function hasPending() {
103
+ const gateway = ctx.get('typertGateway')
104
+ if (gateway === undefined || typeof gateway.getPendingRemoteEvents !== 'function') return false
105
+ try {
106
+ // Only a Session whose turn is still live can be waiting for the user; a
107
+ // request left over from a closed or idle Session must not keep the light amber.
108
+ return gateway.getPendingRemoteEvents().some(entry =>
109
+ (entry.event === 'user-questions/request' || entry.event === 'approval/request') &&
110
+ active.has(entry.agentId))
111
+ } catch (error) {
112
+ console.warn('completion-traffic-light: could not read pending requests', error)
113
+ return false
114
+ }
115
+ }
116
+ function sync() {
117
+ publish(hasPending() ? 'waiting' : active.size > 0 ? 'running' : (started ? 'done' : 'idle'))
118
+ }
119
+ const pendingTimer = setInterval(sync, 300)
120
+ ctx.effect(() => () => clearInterval(pendingTimer))
121
+
122
+ ctx.on('api-session/status', (sessionId, running) => {
123
+ if (running) {
124
+ active.add(sessionId)
125
+ started = true
126
+ } else {
127
+ active.delete(sessionId)
128
+ }
129
+ sync()
130
+ })
131
+
132
+ const agents = ctx.get('agents')
133
+ if (agents !== undefined) {
134
+ for (const agent of agents.list()) {
135
+ if (agent.status !== 'running') continue
136
+ active.add(agent.session.id)
137
+ started = true
138
+ }
139
+ sync()
140
+ }
141
+ }
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Completion traffic light",
4
+ "description": "Shows red, amber, or green under the composer for the current session: working, waiting for you, or finished."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "任务完成红绿灯",
4
+ "description": "在当前会话的输入框下方显示红黄绿灯:运行中、等待你处理、已完成。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,33 @@
1
- {
2
- "name": "dsh-completion-traffic-light",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "dsh-completion-traffic-light",
3
+ "version": "1.0.0",
4
+ "description": "Traffic light under the composer that reports whether the current task is running, waiting for you, or finished.",
5
+ "author": "LuckYur",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/LuckYur/completion-traffic-light.git"
9
+ },
10
+ "homepage": "https://github.com/LuckYur/completion-traffic-light#readme",
11
+ "type": "module",
12
+ "license": "MIT",
13
+ "keywords": ["dsh-plugin", "dsh", "traffic-light", "desktop", "notification"],
14
+ "engines": { "dsh": ">=0.2.0" },
15
+ "exports": {
16
+ ".": "./index.js",
17
+ "./client": "./client.js",
18
+ "./locale/*.json": "./locale/*.json",
19
+ "./icon": "./icon.svg"
20
+ },
21
+ "files": ["index.js", "client.js", "float-window.ps1", "cordis.patch.yml", "locale/*.json", "icon.svg", "assets", "README.md", "LICENSE"],
22
+ "dsh": {
23
+ "bundle": { "patch": "./cordis.patch.yml" },
24
+ "client": {
25
+ "platform": "web",
26
+ "inject": [
27
+ "@deepseek-ai/dsh-client-ui-conversation",
28
+ "@deepseek-ai/dsh-client-ui-session",
29
+ "@deepseek-ai/dsh-client-locale"
30
+ ]
31
+ }
32
+ }
33
+ }