dsh-task-traffic-light 0.0.0-stage → 0.3.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 +21 -0
- package/README.md +89 -2
- package/README.zh.md +88 -0
- package/client.js +125 -0
- package/cordis.patch.yml +3 -0
- package/icon.svg +7 -0
- package/index.js +501 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +54 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wunankun
|
|
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,90 @@
|
|
|
1
|
-
#
|
|
1
|
+
# DSH Task Traffic Light
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A floating traffic light for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) on macOS. It sits at the edge of your screen and tells you what your agents are doing — without switching windows to find out.
|
|
4
|
+
|
|
5
|
+
[中文说明](README.zh.md) · [MIT](LICENSE)
|
|
6
|
+
|
|
7
|
+
## Three lamps, three facts
|
|
8
|
+
|
|
9
|
+
| Lamp | Lit while | Click it and it |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| 🔴 red | at least one top-level session is running | — (informational) |
|
|
12
|
+
| 🟡 yellow | a session waits for your approval or answer | brings DSH forward and opens the **first** waiting session |
|
|
13
|
+
| 🟢 green | a finished session still shows its unread dot in DSH | brings DSH forward and opens the **oldest** unread session |
|
|
14
|
+
|
|
15
|
+
The lamps are independent: a red and a green lamp can be lit at the same time.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
**1 — the plugin** (inside DSH):
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
dsh plugin add dsh-task-traffic-light
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or install it from the plugin market in the app. Most setups need a page refresh afterwards.
|
|
26
|
+
|
|
27
|
+
**2 — the app:**
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
curl -fsSL https://raw.githubusercontent.com/wunankun/dsh-task-traffic-light/main/scripts/install-app.sh | sh
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The script installs `TaskTrafficLight.app` into `/Applications` and launches it. Prefer to do it by hand? Download `TaskTrafficLight.zip` from [Releases](https://github.com/wunankun/dsh-task-traffic-light/releases/latest), unzip, drag it to Applications, and right-click → Open the first time (the build is ad-hoc signed, not notarized).
|
|
34
|
+
|
|
35
|
+
**3 — go.** Restart DSH, refresh its page, and put the lamp where you like. Drag it anywhere; the position is remembered.
|
|
36
|
+
|
|
37
|
+
## The green lamp follows DSH, not a timestamp
|
|
38
|
+
|
|
39
|
+
DSH already puts a small green dot in front of a session that finished while you were looking elsewhere. That dot is the truth this app renders:
|
|
40
|
+
|
|
41
|
+
- the lamp is lit while at least one session carries that dot;
|
|
42
|
+
- opening the session — by clicking the lamp or any other way — clears the dot, and the lamp follows within a second;
|
|
43
|
+
- the lamp goes out only when the last dot is gone.
|
|
44
|
+
|
|
45
|
+
With several unread sessions, each click opens the oldest one and clears it, so clicking twice walks a small queue.
|
|
46
|
+
|
|
47
|
+
## How it works
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
DSH Host plugin ──writes──> ~/.dsh/task-traffic-light/state.json <──reads── TaskTrafficLight.app
|
|
51
|
+
▲ │
|
|
52
|
+
└────── /api/task-light/focus (authenticated, same-origin) ◀── focus.json ┘
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
- The plugin writes a snapshot: running count, pending interactions, waiting session ids, unread session ids, token speed.
|
|
56
|
+
- The app polls that file and draws the lamps.
|
|
57
|
+
- A click writes `focus.json`; the plugin validates it against the lamp it came from and hands it to the Web UI over DSH's own authenticated local channel. The page opens the session and acknowledges the request.
|
|
58
|
+
- Subagent sessions are filtered out: they have no row to open, so they can never hold a lamp on.
|
|
59
|
+
|
|
60
|
+
## Privacy
|
|
61
|
+
|
|
62
|
+
No listening port. No outbound network request. No shell command is executed. The plugin writes one JSON file under `~/.dsh/task-traffic-light/`; the app writes one more when you click a lamp. The whole thing is about 600 lines of JavaScript and 500 lines of Swift — small enough to read in one sitting.
|
|
63
|
+
|
|
64
|
+
## Requirements
|
|
65
|
+
|
|
66
|
+
- macOS 13 or later, Apple silicon or Intel (the release build is universal)
|
|
67
|
+
- DeepSeek Harness 0.2.1 or later with a profile you can add plugins to
|
|
68
|
+
|
|
69
|
+
The app's own menus are in Chinese for now — a localization PR would be very welcome.
|
|
70
|
+
|
|
71
|
+
## Troubleshooting
|
|
72
|
+
|
|
73
|
+
**All lamps stay dark.** No fresh `state.json` within 10 seconds means "DSH is not running". Check the plugin is enabled (`dsh plugin list`), then `tail -f ~/.dsh/task-traffic-light/state.json`.
|
|
74
|
+
|
|
75
|
+
**Clicking does nothing.** The click is applied by the DSH page, so it needs a page that has loaded the plugin's client half: refresh DSH once after installing. A request older than 30 seconds expires quietly.
|
|
76
|
+
|
|
77
|
+
**The lamp shows DSH as online but everything is idle.** The plugin only counts top-level sessions; subagents never light anything on their own.
|
|
78
|
+
|
|
79
|
+
## Build from source
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
git clone https://github.com/wunankun/dsh-task-traffic-light
|
|
83
|
+
cd dsh-task-traffic-light
|
|
84
|
+
./macos/build.sh # universal binary, needs the Xcode command line tools
|
|
85
|
+
open macos/TaskTrafficLight.app
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
MIT © 2026 wunankun
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# DSH 任务红绿灯
|
|
2
|
+
|
|
3
|
+
给 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 用的 macOS 悬浮红绿灯。贴在屏幕边上,不用切窗口就知道几个 agent 在干嘛、哪个在等你。
|
|
4
|
+
|
|
5
|
+
[English](README.md) · [MIT](LICENSE)
|
|
6
|
+
|
|
7
|
+
## 三盏灯,三件事
|
|
8
|
+
|
|
9
|
+
| 灯 | 什么时候亮 | 点一下 |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| 🔴 红灯 | 至少有一个顶层会话在跑 | ——(只是显示) |
|
|
12
|
+
| 🟡 黄灯 | 有会话在等你批准或回答 | 把 DSH 带到最前,切到**第一个**在等的会话 |
|
|
13
|
+
| 🟢 绿灯 | 有会话跑完了,DSH 里那颗未读绿点还没消 | 把 DSH 带到最前,切到**最早完成**的那个 |
|
|
14
|
+
|
|
15
|
+
三盏灯互相独立,红灯和绿灯可以同时亮。
|
|
16
|
+
|
|
17
|
+
## 安装
|
|
18
|
+
|
|
19
|
+
**第一步,装插件**(在 DSH 里):
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
dsh plugin add dsh-task-traffic-light
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
也可以在 DSH 的插件市场里点安装。装完刷新一次页面。
|
|
26
|
+
|
|
27
|
+
**第二步,装小应用**:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
curl -fsSL https://raw.githubusercontent.com/wunankun/dsh-task-traffic-light/main/scripts/install-app.sh | sh
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
脚本会把 `TaskTrafficLight.app` 放进 `/Applications` 并打开。想手动也行:[Releases](https://github.com/wunankun/dsh-task-traffic-light/releases/latest) 下载 `TaskTrafficLight.zip`,解压拖进"应用程序",第一次右键 → 打开(ad-hoc 签名,没有公证)。
|
|
34
|
+
|
|
35
|
+
**第三步**:重启 DSH、刷新页面,把灯拖到你顺眼的位置。位置会记住。
|
|
36
|
+
|
|
37
|
+
## 绿灯为什么跟着 DSH 走
|
|
38
|
+
|
|
39
|
+
DSH 本来就会给"跑完了、但你当时没在看"的会话,在列表里标一颗绿点。红绿灯的绿灯就是这颗点的镜子:
|
|
40
|
+
|
|
41
|
+
- 只要还有会话带着绿点,灯就亮着;
|
|
42
|
+
- 你打开那个会话(点灯或者自己点都行),绿点一消,灯一秒内跟着灭;
|
|
43
|
+
- 最后一点消完,绿灯才灭。
|
|
44
|
+
|
|
45
|
+
有好几个没看的时候,每点一次切到最早完成、把它消掉,所以连点两下就是在排队处理。
|
|
46
|
+
|
|
47
|
+
## 它是怎么工作的
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
DSH Host 插件 ──写──> ~/.dsh/task-traffic-light/state.json <──读── TaskTrafficLight.app
|
|
51
|
+
▲ │
|
|
52
|
+
└────── /api/task-light/focus(带认证、同源)◀── focus.json ────────┘
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
- 插件写一份快照:在跑数量、待处理交互、等待中的会话 id、未读完成的会话 id、实时速度。
|
|
56
|
+
- 小应用轮询这个文件画灯。
|
|
57
|
+
- 点击时写 `focus.json`,插件先确认目标会话确实还亮着那盏灯,再通过 DSH 自己的本机认证通道交给前端;页面切过去后回执。
|
|
58
|
+
- 子代理会话被过滤掉:它们在列表里没有行,永远点不掉,所以不能把灯卡住。
|
|
59
|
+
|
|
60
|
+
## 隐私
|
|
61
|
+
|
|
62
|
+
不开端口、不联网、不执行任何命令。插件只在 `~/.dsh/task-traffic-light/` 下写一个 JSON,小应用在你点灯时再写一个。全部代码大约 600 行 JavaScript + 500 行 Swift,抽空能通读一遍。
|
|
63
|
+
|
|
64
|
+
## 环境要求
|
|
65
|
+
|
|
66
|
+
- macOS 13 或更新,Apple 芯片或 Intel(发布包是 universal)
|
|
67
|
+
- DeepSeek Harness 0.2.1 或更新,且能往 profile 里加插件
|
|
68
|
+
|
|
69
|
+
## 出问题怎么办
|
|
70
|
+
|
|
71
|
+
**三盏灯全黑。** 10 秒内没更新过 `state.json` 就按"DSH 没在跑"处理。确认插件启用了(`dsh plugin list`),再 `tail -f ~/.dsh/task-traffic-light/state.json` 看看有没有在刷新。
|
|
72
|
+
|
|
73
|
+
**点了没反应。** 点击是由 DSH 页面执行的,所以页面必须加载到插件的客户端那一半——装完刷新一次页面。超过 30 秒的点击会静默过期。
|
|
74
|
+
|
|
75
|
+
**灯亮着但看着没事。** 插件只统计顶层会话,子代理不会单独点亮任何灯。
|
|
76
|
+
|
|
77
|
+
## 自己编译
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
git clone https://github.com/wunankun/dsh-task-traffic-light
|
|
81
|
+
cd dsh-task-traffic-light
|
|
82
|
+
./macos/build.sh # 编 universal,需要 Xcode 命令行工具
|
|
83
|
+
open macos/TaskTrafficLight.app
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## 许可证
|
|
87
|
+
|
|
88
|
+
MIT © 2026 wunankun
|
package/client.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web half of `dsh-task-traffic-light`.
|
|
3
|
+
*
|
|
4
|
+
* The macOS app writes a click on the yellow or the green lamp as a small
|
|
5
|
+
* file, the Host half exposes it over the authenticated `/api` channel, and
|
|
6
|
+
* this module selects the requested Session in the Web UI. No visible surface
|
|
7
|
+
* is added.
|
|
8
|
+
*
|
|
9
|
+
* It also reports back which Sessions DSH still marks as an unread completion
|
|
10
|
+
* (the green dot in front of a Session row). The green lamp in the macOS app
|
|
11
|
+
* follows that set, so it only goes out once every dot has been cleared.
|
|
12
|
+
*/
|
|
13
|
+
window.__ModuleLoader__.load({
|
|
14
|
+
id: 'dsh-task-traffic-light',
|
|
15
|
+
factory() {
|
|
16
|
+
const ROUTE = 'api/task-light/focus'
|
|
17
|
+
const POLL_MS = 500
|
|
18
|
+
const STORAGE_KEY = 'dsh-task-light.last-focus.v1'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Read the last click this page already applied, so a reload does not
|
|
22
|
+
* navigate again before the Host retires the request.
|
|
23
|
+
* @returns {string} nonce, or an empty string.
|
|
24
|
+
*/
|
|
25
|
+
function lastNonce() {
|
|
26
|
+
try {
|
|
27
|
+
return window.localStorage.getItem(STORAGE_KEY) ?? ''
|
|
28
|
+
} catch (_error) {
|
|
29
|
+
return ''
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Remember one applied click without making storage failure fatal.
|
|
35
|
+
* @param {string} nonce - request identity.
|
|
36
|
+
*/
|
|
37
|
+
function rememberNonce(nonce) {
|
|
38
|
+
try {
|
|
39
|
+
window.localStorage.setItem(STORAGE_KEY, nonce)
|
|
40
|
+
} catch (_error) {
|
|
41
|
+
// Private mode or a disabled store only means a reload may repeat it.
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
inject: ['uiWorkspace', 'uiSession'],
|
|
47
|
+
apply(ctx) {
|
|
48
|
+
let disposed = false
|
|
49
|
+
let polling = false
|
|
50
|
+
let seen = lastNonce()
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Sessions whose completion the user still has not opened, as DSH's
|
|
54
|
+
* own reminder dots see them.
|
|
55
|
+
* @returns {string[]} Session ids; empty when the status source is not ready.
|
|
56
|
+
*/
|
|
57
|
+
function unreadSessionIds() {
|
|
58
|
+
try {
|
|
59
|
+
const ids = []
|
|
60
|
+
for (const [id, status] of ctx.uiSession.sessionStatus.getSnapshot()) {
|
|
61
|
+
if (status !== undefined && status.completionUnread === true) ids.push(String(id))
|
|
62
|
+
}
|
|
63
|
+
return ids
|
|
64
|
+
} catch (_error) {
|
|
65
|
+
// Before the Session source settles there is simply nothing to report.
|
|
66
|
+
return []
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Send one action to the Host half over the shared API channel.
|
|
72
|
+
* @param {object} body - action payload.
|
|
73
|
+
* @returns {Promise<object | null>} decoded result, or null when unavailable.
|
|
74
|
+
*/
|
|
75
|
+
async function post(body) {
|
|
76
|
+
const response = await window.fetch(ROUTE, {
|
|
77
|
+
method: 'POST',
|
|
78
|
+
headers: { 'content-type': 'application/json' },
|
|
79
|
+
body: JSON.stringify(body),
|
|
80
|
+
credentials: 'same-origin',
|
|
81
|
+
})
|
|
82
|
+
if (!response.ok) return null
|
|
83
|
+
return await response.json()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function poll() {
|
|
87
|
+
if (polling || disposed) return
|
|
88
|
+
polling = true
|
|
89
|
+
try {
|
|
90
|
+
// One request carries both directions: which Sessions still have a
|
|
91
|
+
// reminder dot, and whether a lamp click waits to be applied.
|
|
92
|
+
const result = await post({ action: 'poll', completed: unreadSessionIds() })
|
|
93
|
+
const request = result?.request
|
|
94
|
+
if (request === null || typeof request !== 'object') return
|
|
95
|
+
const { sessionId, nonce } = request
|
|
96
|
+
if (typeof sessionId !== 'string' || sessionId.length === 0) return
|
|
97
|
+
if (typeof nonce !== 'string' || nonce.length === 0 || nonce === seen) return
|
|
98
|
+
seen = nonce
|
|
99
|
+
rememberNonce(nonce)
|
|
100
|
+
try {
|
|
101
|
+
ctx.uiWorkspace.openSession(sessionId)
|
|
102
|
+
} catch (_error) {
|
|
103
|
+
// A Session that disappeared between the click and the poll is
|
|
104
|
+
// nothing the user can act on here.
|
|
105
|
+
}
|
|
106
|
+
await post({ action: 'ack', nonce })
|
|
107
|
+
} catch (_error) {
|
|
108
|
+
// The route appears with the Host plugin and disappears while it
|
|
109
|
+
// reloads; the next tick retries.
|
|
110
|
+
} finally {
|
|
111
|
+
polling = false
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
ctx.effect(() => {
|
|
116
|
+
const ticker = window.setInterval(() => { void poll() }, POLL_MS)
|
|
117
|
+
return () => {
|
|
118
|
+
disposed = true
|
|
119
|
+
window.clearInterval(ticker)
|
|
120
|
+
}
|
|
121
|
+
}, 'task-light-bridge: focus poll')
|
|
122
|
+
},
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
})
|
package/cordis.patch.yml
ADDED
package/icon.svg
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36">
|
|
2
|
+
<rect x="10" y="3" width="16" height="30" rx="4.5" fill="#26262b"/>
|
|
3
|
+
<rect x="10.5" y="3.5" width="15" height="29" rx="4" fill="none" stroke="#4a4a52"/>
|
|
4
|
+
<circle cx="18" cy="10.5" r="3.4" fill="#ff453a"/>
|
|
5
|
+
<circle cx="18" cy="18" r="3.4" fill="#ffd60a"/>
|
|
6
|
+
<circle cx="18" cy="25.5" r="3.4" fill="#30d158"/>
|
|
7
|
+
</svg>
|
package/index.js
ADDED
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host half of the task traffic light: publishes a tiny state file that the
|
|
3
|
+
* standalone TaskTrafficLight macOS app watches. No UI and no network access.
|
|
4
|
+
*
|
|
5
|
+
* The three lamps are independent: running work, a pending human interaction,
|
|
6
|
+
* and an unread completion can all be true at once.
|
|
7
|
+
*
|
|
8
|
+
* A click on the yellow or the green lamp is delivered by the macOS app as
|
|
9
|
+
* `focus.json` and handed to the Web UI over the local Connection RPC channel,
|
|
10
|
+
* where the client half selects the target Session.
|
|
11
|
+
*
|
|
12
|
+
* The green lamp is owned by the Web UI: the client half reports which
|
|
13
|
+
* Sessions still carry a completion-reminder dot ("finished while you were
|
|
14
|
+
* elsewhere, not opened since"), so the lamp only goes out once the user has
|
|
15
|
+
* opened every such Session and DSH has cleared its own dot.
|
|
16
|
+
*/
|
|
17
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
|
|
18
|
+
import { homedir } from 'node:os'
|
|
19
|
+
import { join } from 'node:path'
|
|
20
|
+
|
|
21
|
+
export const name = 'task-traffic-light'
|
|
22
|
+
export const inject = ['agents']
|
|
23
|
+
|
|
24
|
+
const STATE_DIR = join(homedir(), '.dsh', 'task-traffic-light')
|
|
25
|
+
const STATE_FILE = join(STATE_DIR, 'state.json')
|
|
26
|
+
/** Click request written by the macOS app; read here and handed to the Web UI. */
|
|
27
|
+
const FOCUS_FILE = join(STATE_DIR, 'focus.json')
|
|
28
|
+
/** How long an unanswered lamp click stays valid, in milliseconds. */
|
|
29
|
+
const FOCUS_TTL_MS = 30_000
|
|
30
|
+
/** How often the snapshot is considered for a rewrite. */
|
|
31
|
+
const TICK_MS = 500
|
|
32
|
+
/** A stale state file must still be refreshed at least this often. */
|
|
33
|
+
const HEARTBEAT_MS = 2_500
|
|
34
|
+
/** Sliding window used to estimate the live output speed. */
|
|
35
|
+
const SPEED_WINDOW_MS = 2_500
|
|
36
|
+
/** The shortest span a fresh stream is averaged over, so the first second is not inflated. */
|
|
37
|
+
const MIN_SPAN_MS = 700
|
|
38
|
+
/** State file layout version; the macOS app tolerates older and newer fields. */
|
|
39
|
+
const STATE_VERSION = 5
|
|
40
|
+
/** Most Session ids one report may carry; a guard against a runaway client. */
|
|
41
|
+
const MAX_REPORTED = 200
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Publish task state to the macOS app.
|
|
45
|
+
*
|
|
46
|
+
* Only top-level sessions count: a subagent belongs to the session that
|
|
47
|
+
* started it, so its work never adds to the red count and its stop never
|
|
48
|
+
* lights green on its own. Pending questions and approvals still count
|
|
49
|
+
* globally because they always need the human.
|
|
50
|
+
*/
|
|
51
|
+
export function apply(ctx) {
|
|
52
|
+
/** @type {Map<object, boolean>} top-level agent -> running */
|
|
53
|
+
const sessions = new Map()
|
|
54
|
+
/** @type {WeakSet<object>} agents owned by a session, excluded from counts */
|
|
55
|
+
const subagents = new WeakSet()
|
|
56
|
+
/** @type {Map<symbol, { kind: string, sessionId: string | undefined, since: number }>} pending interaction -> details */
|
|
57
|
+
const pending = new Map()
|
|
58
|
+
/** @type {Map<object, Array<{ t: number, tokens: number }>>} agent -> recent output samples */
|
|
59
|
+
const streams = new Map()
|
|
60
|
+
/** Session ids the Web UI still marks with a completion-reminder dot, newest report wins. */
|
|
61
|
+
let reportedUnread = []
|
|
62
|
+
/** @type {Map<string, number>} Session id -> when it last stopped running, for the green queue. */
|
|
63
|
+
const stoppedAt = new Map()
|
|
64
|
+
/** Latest top-level completion, kept until a newer one replaces it. */
|
|
65
|
+
let doneAt = 0
|
|
66
|
+
/** Latest yellow-lamp click waiting for the Web UI, or null once answered. */
|
|
67
|
+
let focusRequest = null
|
|
68
|
+
/** Contents of the last focus file read, so an unchanged file is not re-parsed. */
|
|
69
|
+
let focusFileSignature = ''
|
|
70
|
+
let lastSignature = ''
|
|
71
|
+
let lastWriteAt = 0
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Whether an agent is a subagent child rather than a session the user opened.
|
|
75
|
+
* @param {object} agent - live agent.
|
|
76
|
+
* @returns {boolean} true when the session header marks it as a subagent.
|
|
77
|
+
*/
|
|
78
|
+
function isSubagent(agent) {
|
|
79
|
+
return agent.session?.header?.origin === 'subagent'
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Session the user sees for one pending interaction: a subagent belongs to
|
|
84
|
+
* the top-level Session that opened it, so walking up its live parents picks
|
|
85
|
+
* the row a click should select.
|
|
86
|
+
* @param {object | undefined} agent - agent that asked for the human.
|
|
87
|
+
* @returns {string | undefined} top-level Session id when known.
|
|
88
|
+
*/
|
|
89
|
+
function visibleSessionId(agent) {
|
|
90
|
+
let header = agent?.session?.header
|
|
91
|
+
let guard = 0
|
|
92
|
+
while (header?.origin === 'subagent' && header.parentSession !== undefined && guard < 16) {
|
|
93
|
+
const parent = ctx.agents.get(header.parentSession)
|
|
94
|
+
if (parent?.session === undefined) break
|
|
95
|
+
header = parent.session.header
|
|
96
|
+
guard += 1
|
|
97
|
+
}
|
|
98
|
+
return header?.id
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Waiting Sessions in request order, without duplicates. The first one is
|
|
103
|
+
* what a click on the yellow lamp selects.
|
|
104
|
+
* @returns {string[]} Session ids.
|
|
105
|
+
*/
|
|
106
|
+
function waitingSessionIds() {
|
|
107
|
+
const ids = []
|
|
108
|
+
const seen = new Set()
|
|
109
|
+
for (const entry of pending.values()) {
|
|
110
|
+
if (entry.sessionId === undefined || seen.has(entry.sessionId)) continue
|
|
111
|
+
seen.add(entry.sessionId)
|
|
112
|
+
ids.push(entry.sessionId)
|
|
113
|
+
}
|
|
114
|
+
return ids
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Session id behind one tracked agent.
|
|
119
|
+
* @param {object} agent - live agent.
|
|
120
|
+
* @returns {string | undefined} Session id when the agent exposes one.
|
|
121
|
+
*/
|
|
122
|
+
function sessionIdOf(agent) {
|
|
123
|
+
return agent?.session?.header?.id
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Sessions the user still owes a look, oldest completion first. Only ids the
|
|
128
|
+
* Web UI reported as unread count, and only top-level Sessions are kept:
|
|
129
|
+
* a subagent row never appears in the list and could never be cleared by
|
|
130
|
+
* opening it, so it must not hold the green lamp on.
|
|
131
|
+
* @returns {string[]} Session ids, first one is what a click on the green lamp selects.
|
|
132
|
+
*/
|
|
133
|
+
function completedSessionIds() {
|
|
134
|
+
const known = new Set()
|
|
135
|
+
for (const agent of sessions.keys()) {
|
|
136
|
+
const id = sessionIdOf(agent)
|
|
137
|
+
if (id !== undefined) known.add(id)
|
|
138
|
+
}
|
|
139
|
+
const ids = reportedUnread.filter(id => known.has(id))
|
|
140
|
+
// Array.prototype.sort is stable, so ids without a stop stamp keep report order.
|
|
141
|
+
ids.sort((left, right) => (stoppedAt.get(left) ?? Number.MAX_SAFE_INTEGER)
|
|
142
|
+
- (stoppedAt.get(right) ?? Number.MAX_SAFE_INTEGER))
|
|
143
|
+
return ids
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Replace the client-reported unread set, rejecting malformed entries.
|
|
148
|
+
* @param {unknown} input - candidate list from the Web UI.
|
|
149
|
+
* @returns {boolean} true when the stored set changed.
|
|
150
|
+
*/
|
|
151
|
+
function setReportedUnread(input) {
|
|
152
|
+
const next = []
|
|
153
|
+
const seen = new Set()
|
|
154
|
+
if (Array.isArray(input)) {
|
|
155
|
+
for (const value of input) {
|
|
156
|
+
if (typeof value !== 'string' || value.length === 0 || value.length > 200) continue
|
|
157
|
+
if (seen.has(value)) continue
|
|
158
|
+
seen.add(value)
|
|
159
|
+
next.push(value)
|
|
160
|
+
if (next.length >= MAX_REPORTED) break
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const unchanged = next.length === reportedUnread.length
|
|
164
|
+
&& next.every((id, index) => id === reportedUnread[index])
|
|
165
|
+
if (unchanged) return false
|
|
166
|
+
reportedUnread = next
|
|
167
|
+
return true
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
for (const agent of ctx.agents.list()) {
|
|
171
|
+
if (isSubagent(agent)) {
|
|
172
|
+
subagents.add(agent)
|
|
173
|
+
continue
|
|
174
|
+
}
|
|
175
|
+
sessions.set(agent, agent.status === 'running')
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function runningCount() {
|
|
179
|
+
let count = 0
|
|
180
|
+
for (const running of sessions.values()) if (running) count += 1
|
|
181
|
+
return count
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function summaryTone() {
|
|
185
|
+
if (pending.size > 0) return 'waiting'
|
|
186
|
+
if (runningCount() > 0) return 'running'
|
|
187
|
+
if (doneAt > 0 || completedSessionIds().length > 0) return 'done'
|
|
188
|
+
return 'idle'
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Rough output-token estimate for one streamed delta: CJK and other wide
|
|
193
|
+
* characters cost about one token each, everything else about four
|
|
194
|
+
* characters per token.
|
|
195
|
+
* @param {string} text - one streamed delta.
|
|
196
|
+
* @returns {number} estimated tokens.
|
|
197
|
+
*/
|
|
198
|
+
function estimateTokens(text) {
|
|
199
|
+
let wide = 0
|
|
200
|
+
let narrow = 0
|
|
201
|
+
for (const character of text) {
|
|
202
|
+
const code = character.codePointAt(0)
|
|
203
|
+
if (code >= 0x2e80) wide += 1
|
|
204
|
+
else if (code > 0x20 && code !== 0x7f) narrow += 1
|
|
205
|
+
}
|
|
206
|
+
return wide + narrow / 4
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Record one streamed delta and drop samples that left the window.
|
|
211
|
+
* @param {object} agent - the agent that produced the delta.
|
|
212
|
+
* @param {unknown} frame - one `agent/assistant-stream` publication.
|
|
213
|
+
*/
|
|
214
|
+
function recordFrame(agent, frame) {
|
|
215
|
+
if (frame === undefined || frame === null || frame.type !== 'chunk') return
|
|
216
|
+
const chunk = frame.chunk
|
|
217
|
+
if (chunk === undefined || chunk === null) return
|
|
218
|
+
let text
|
|
219
|
+
if (chunk.type === 'text-delta' || chunk.type === 'reasoning-delta') text = chunk.text
|
|
220
|
+
else if (chunk.type === 'tool-call-delta') text = chunk.argumentsDelta
|
|
221
|
+
if (typeof text !== 'string' || text.length === 0) return
|
|
222
|
+
const tokens = estimateTokens(text)
|
|
223
|
+
if (tokens <= 0) return
|
|
224
|
+
const now = Date.now()
|
|
225
|
+
const samples = streams.get(agent)
|
|
226
|
+
if (samples === undefined) streams.set(agent, [{ t: now, tokens }])
|
|
227
|
+
else samples.push({ t: now, tokens })
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Sum the in-window output across every streaming agent and divide by the
|
|
232
|
+
* watched span.
|
|
233
|
+
* @param {number} now - current time in milliseconds.
|
|
234
|
+
* @returns {number} estimated tokens per second.
|
|
235
|
+
*/
|
|
236
|
+
function currentSpeed(now) {
|
|
237
|
+
const cutoff = now - SPEED_WINDOW_MS
|
|
238
|
+
let tokens = 0
|
|
239
|
+
let earliest = now
|
|
240
|
+
for (const [agent, samples] of streams) {
|
|
241
|
+
let expired = 0
|
|
242
|
+
while (expired < samples.length && samples[expired].t < cutoff) expired += 1
|
|
243
|
+
if (expired > 0) samples.splice(0, expired)
|
|
244
|
+
if (samples.length === 0) {
|
|
245
|
+
streams.delete(agent)
|
|
246
|
+
continue
|
|
247
|
+
}
|
|
248
|
+
for (const sample of samples) {
|
|
249
|
+
tokens += sample.tokens
|
|
250
|
+
if (sample.t < earliest) earliest = sample.t
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (tokens <= 0) return 0
|
|
254
|
+
const span = Math.max(MIN_SPAN_MS, now - Math.max(cutoff, earliest))
|
|
255
|
+
return (tokens * 1000) / span
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Read a new click request written by the macOS app. An unchanged file is
|
|
260
|
+
* ignored, and a click only navigates to a Session the lamp it came from
|
|
261
|
+
* still stands for, so a stale request cannot switch the page on its own.
|
|
262
|
+
* @param {number} now - current time in milliseconds.
|
|
263
|
+
*/
|
|
264
|
+
function readFocusFile(now) {
|
|
265
|
+
let text
|
|
266
|
+
try {
|
|
267
|
+
text = readFileSync(FOCUS_FILE, 'utf8')
|
|
268
|
+
} catch (error) {
|
|
269
|
+
return
|
|
270
|
+
}
|
|
271
|
+
if (text === focusFileSignature) return
|
|
272
|
+
focusFileSignature = text
|
|
273
|
+
let request
|
|
274
|
+
try {
|
|
275
|
+
request = JSON.parse(text)
|
|
276
|
+
} catch (error) {
|
|
277
|
+
return
|
|
278
|
+
}
|
|
279
|
+
if (request === null || typeof request !== 'object') return
|
|
280
|
+
const { sessionId, nonce } = request
|
|
281
|
+
const lamp = request.lamp === 'green' ? 'green' : 'yellow'
|
|
282
|
+
const at = typeof request.at === 'number' ? request.at : now
|
|
283
|
+
if (typeof sessionId !== 'string' || typeof nonce !== 'string') return
|
|
284
|
+
if (now - at > FOCUS_TTL_MS || at - now > 5_000) return
|
|
285
|
+
const targets = lamp === 'green' ? completedSessionIds() : waitingSessionIds()
|
|
286
|
+
if (!targets.includes(sessionId)) return
|
|
287
|
+
focusRequest = { sessionId, nonce, at, lamp }
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Current click request, if it has not expired.
|
|
292
|
+
* @returns {{ sessionId: string, nonce: string, at: number, lamp: 'yellow' | 'green' } | null} request.
|
|
293
|
+
*/
|
|
294
|
+
function takeFocusRequest() {
|
|
295
|
+
if (focusRequest === null) return null
|
|
296
|
+
if (Date.now() - focusRequest.at > FOCUS_TTL_MS) {
|
|
297
|
+
focusRequest = null
|
|
298
|
+
return null
|
|
299
|
+
}
|
|
300
|
+
return { ...focusRequest }
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Retire a click request once the Web UI has selected its Session.
|
|
305
|
+
* @param {unknown} nonce - request identity echoed by the client.
|
|
306
|
+
* @returns {boolean} true when the request was current or already retired.
|
|
307
|
+
*/
|
|
308
|
+
function acknowledgeFocus(nonce) {
|
|
309
|
+
if (focusRequest === null) return true
|
|
310
|
+
if (typeof nonce !== 'string' || focusRequest.nonce !== nonce) return false
|
|
311
|
+
focusRequest = null
|
|
312
|
+
return true
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function buildPayload() {
|
|
316
|
+
const now = Date.now()
|
|
317
|
+
const running = runningCount()
|
|
318
|
+
const speed = running > 0 ? Math.round(currentSpeed(now) * 10) / 10 : null
|
|
319
|
+
return {
|
|
320
|
+
version: STATE_VERSION,
|
|
321
|
+
tone: summaryTone(),
|
|
322
|
+
sessions: sessions.size,
|
|
323
|
+
running,
|
|
324
|
+
pending: pending.size,
|
|
325
|
+
waitingSessions: waitingSessionIds(),
|
|
326
|
+
completedSessions: completedSessionIds(),
|
|
327
|
+
updatedAt: now,
|
|
328
|
+
doneAt: doneAt > 0 ? doneAt : null,
|
|
329
|
+
tokensPerSecond: speed,
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Rewrite the state file when something visible changed, or when the
|
|
335
|
+
* heartbeat interval elapsed.
|
|
336
|
+
* @param {boolean} force - write even when the snapshot is unchanged.
|
|
337
|
+
*/
|
|
338
|
+
function publish(force = false) {
|
|
339
|
+
const now = Date.now()
|
|
340
|
+
readFocusFile(now)
|
|
341
|
+
const payload = buildPayload()
|
|
342
|
+
const signature = JSON.stringify([payload.running, payload.pending, payload.sessions,
|
|
343
|
+
payload.waitingSessions, payload.completedSessions, payload.doneAt, payload.tokensPerSecond])
|
|
344
|
+
if (!force && signature === lastSignature && now - lastWriteAt < HEARTBEAT_MS) return
|
|
345
|
+
try {
|
|
346
|
+
mkdirSync(STATE_DIR, { recursive: true })
|
|
347
|
+
const temporary = STATE_FILE + '.tmp'
|
|
348
|
+
writeFileSync(temporary, JSON.stringify(payload) + '\n', 'utf8')
|
|
349
|
+
renameSync(temporary, STATE_FILE)
|
|
350
|
+
lastSignature = signature
|
|
351
|
+
lastWriteAt = now
|
|
352
|
+
} catch (error) {
|
|
353
|
+
// The app treats a missing or stale file as idle; never break the Host.
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Track one pending interaction until the human answers it.
|
|
359
|
+
* @param {string} kind - approval or question.
|
|
360
|
+
* @param {object | undefined} agent - agent the interaction belongs to.
|
|
361
|
+
* @returns {() => void} release function.
|
|
362
|
+
*/
|
|
363
|
+
function trackPending(kind, agent) {
|
|
364
|
+
const key = Symbol(kind)
|
|
365
|
+
pending.set(key, { kind, sessionId: visibleSessionId(agent), since: Date.now() })
|
|
366
|
+
publish(true)
|
|
367
|
+
return () => {
|
|
368
|
+
if (!pending.delete(key)) return
|
|
369
|
+
publish(true)
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// These are waterfalls that DSH itself forwards to the web client, which
|
|
374
|
+
// awaits the human answer before calling `next()`. Registering with
|
|
375
|
+
// `prepend` keeps this bookkeeping outside that forwarder; otherwise the
|
|
376
|
+
// pending state would only appear after the answer arrived.
|
|
377
|
+
ctx.on('approval/request', async (request, next) => {
|
|
378
|
+
const release = trackPending('approval', request.agent)
|
|
379
|
+
try {
|
|
380
|
+
return await next()
|
|
381
|
+
} finally {
|
|
382
|
+
release()
|
|
383
|
+
}
|
|
384
|
+
}, { prepend: true })
|
|
385
|
+
|
|
386
|
+
ctx.on('user-questions/request', async (request, next) => {
|
|
387
|
+
const release = trackPending('question', request.agent)
|
|
388
|
+
try {
|
|
389
|
+
return await next()
|
|
390
|
+
} finally {
|
|
391
|
+
release()
|
|
392
|
+
}
|
|
393
|
+
}, { prepend: true })
|
|
394
|
+
|
|
395
|
+
ctx.on('agent/assistant-stream', ({ agent, frame }) => {
|
|
396
|
+
recordFrame(agent, frame)
|
|
397
|
+
})
|
|
398
|
+
|
|
399
|
+
ctx.on('agent/created', ({ agent }) => {
|
|
400
|
+
if (isSubagent(agent)) {
|
|
401
|
+
subagents.add(agent)
|
|
402
|
+
return
|
|
403
|
+
}
|
|
404
|
+
sessions.set(agent, agent.status === 'running')
|
|
405
|
+
publish(true)
|
|
406
|
+
})
|
|
407
|
+
|
|
408
|
+
ctx.on('agent/status', ({ agent, status }) => {
|
|
409
|
+
if (subagents.has(agent)) return
|
|
410
|
+
const wasRunning = sessions.get(agent) === true
|
|
411
|
+
sessions.set(agent, status === 'running')
|
|
412
|
+
const sessionId = sessionIdOf(agent)
|
|
413
|
+
if (sessionId !== undefined) {
|
|
414
|
+
if (status === 'running') stoppedAt.delete(sessionId)
|
|
415
|
+
else if (wasRunning) stoppedAt.set(sessionId, Date.now())
|
|
416
|
+
}
|
|
417
|
+
if (wasRunning && status !== 'running') doneAt = Date.now()
|
|
418
|
+
publish(true)
|
|
419
|
+
})
|
|
420
|
+
|
|
421
|
+
ctx.on('agent/disposed', ({ agent }) => {
|
|
422
|
+
streams.delete(agent)
|
|
423
|
+
if (subagents.has(agent)) return
|
|
424
|
+
const sessionId = sessionIdOf(agent)
|
|
425
|
+
if (sessionId !== undefined) stoppedAt.delete(sessionId)
|
|
426
|
+
sessions.delete(agent)
|
|
427
|
+
publish(true)
|
|
428
|
+
})
|
|
429
|
+
|
|
430
|
+
// The click is only a UI navigation; it travels over the same authenticated
|
|
431
|
+
// Connection transport as the rest of the Web client, so no extra port,
|
|
432
|
+
// server, or network access is opened.
|
|
433
|
+
// The click is only a UI navigation. It travels over the same authenticated
|
|
434
|
+
// `/api` Fetch channel as the rest of the Web client, so no extra port,
|
|
435
|
+
// server, or network access is opened. An exact Fetch route is used instead
|
|
436
|
+
// of a logical RPC channel because the Connection service in this release
|
|
437
|
+
// cannot mount a new physical route from the profile's composition.
|
|
438
|
+
ctx.inject(['connection'], (scope) => {
|
|
439
|
+
scope.effect(() => {
|
|
440
|
+
const dispose = scope.connection.fetch.register({
|
|
441
|
+
path: '/api/task-light/focus',
|
|
442
|
+
methods: ['POST'],
|
|
443
|
+
requestBody: 'buffered',
|
|
444
|
+
fetch: async request => {
|
|
445
|
+
let body
|
|
446
|
+
try {
|
|
447
|
+
body = await request.json()
|
|
448
|
+
} catch (error) {
|
|
449
|
+
return Response.json({ error: 'body is not JSON' }, { status: 400 })
|
|
450
|
+
}
|
|
451
|
+
if (body === null || typeof body !== 'object') {
|
|
452
|
+
return Response.json({ error: 'body must be an object' }, { status: 400 })
|
|
453
|
+
}
|
|
454
|
+
if (body.action === 'poll') {
|
|
455
|
+
// The page also reports which Sessions still carry a completion
|
|
456
|
+
// dot, so the green lamp follows DSH's own reminder instead of a
|
|
457
|
+
// timestamp the app would have to dismiss on its own.
|
|
458
|
+
if (setReportedUnread(body.completed)) publish(true)
|
|
459
|
+
readFocusFile(Date.now())
|
|
460
|
+
return Response.json({ request: takeFocusRequest() })
|
|
461
|
+
}
|
|
462
|
+
if (body.action === 'ack') {
|
|
463
|
+
return Response.json({ acknowledged: acknowledgeFocus(body.nonce) })
|
|
464
|
+
}
|
|
465
|
+
return Response.json({ error: `unknown action: ${String(body.action)}` }, { status: 400 })
|
|
466
|
+
},
|
|
467
|
+
})
|
|
468
|
+
return () => {
|
|
469
|
+
void dispose()
|
|
470
|
+
}
|
|
471
|
+
}, 'task-light-bridge: focus route')
|
|
472
|
+
})
|
|
473
|
+
|
|
474
|
+
ctx.effect(() => {
|
|
475
|
+
publish(true)
|
|
476
|
+
const ticker = setInterval(() => publish(), TICK_MS)
|
|
477
|
+
if (typeof ticker.unref === 'function') ticker.unref()
|
|
478
|
+
return () => {
|
|
479
|
+
clearInterval(ticker)
|
|
480
|
+
try {
|
|
481
|
+
mkdirSync(STATE_DIR, { recursive: true })
|
|
482
|
+
const temporary = STATE_FILE + '.tmp'
|
|
483
|
+
writeFileSync(temporary, JSON.stringify({
|
|
484
|
+
version: STATE_VERSION,
|
|
485
|
+
tone: 'idle',
|
|
486
|
+
sessions: 0,
|
|
487
|
+
running: 0,
|
|
488
|
+
pending: 0,
|
|
489
|
+
waitingSessions: [],
|
|
490
|
+
completedSessions: [],
|
|
491
|
+
updatedAt: Date.now(),
|
|
492
|
+
doneAt: null,
|
|
493
|
+
tokensPerSecond: null,
|
|
494
|
+
}) + '\n', 'utf8')
|
|
495
|
+
renameSync(temporary, STATE_FILE)
|
|
496
|
+
} catch (error) {
|
|
497
|
+
// A stale file only makes the app show idle after its freshness window.
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}, 'task-light-bridge: publish state')
|
|
501
|
+
}
|
package/locale/en.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Task traffic light",
|
|
4
|
+
"description": "Publishes DeepSeek Harness task state to ~/.dsh/task-traffic-light/state.json so the standalone TaskTrafficLight macOS app can show a red (working), yellow (waiting for you), green (a Session finished unread) or dim green (idle) lamp. While the yellow lamp is lit, clicking it brings DSH to the front and switches to the first waiting session (only the first when several wait at once). The green lamp mirrors the unread completion dots in DSH: clicking it switches to the oldest Session whose dot is still lit, and the lamp goes out only once every dot has been cleared. It adds no DSH UI and sends nothing over the network; disable it when the Mac app is not used."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/zh.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "任务红绿灯",
|
|
4
|
+
"description": "把 DSH 的任务状态写到 ~/.dsh/task-traffic-light/state.json,供独立的 TaskTrafficLight 菜单栏小应用显示红灯(干活中)、黄灯(等你处理)、绿灯(有会话跑完还没看)。黄灯亮时点击黄灯,会聚焦 DSH 并切到第一个等待处理的会话(多个同时等待时只切第一个)。绿灯跟着 DSH 会话行前的绿点走:点击绿灯切到最早完成、还没打开的那个会话,绿点全消了绿灯才灭。它不添加任何 DSH 界面,也不联网;不用这个小应用时可以关掉它。"
|
|
5
|
+
}
|
|
6
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-task-traffic-light",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "A macOS traffic light for DeepSeek Harness: red while sessions work, yellow when one waits for you, green while finished sessions are still unread. Clicking a lit lamp brings DSH to the front and opens the matching session.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"dsh",
|
|
9
|
+
"deepseek-harness",
|
|
10
|
+
"plugin",
|
|
11
|
+
"traffic-light",
|
|
12
|
+
"macos",
|
|
13
|
+
"menu-bar",
|
|
14
|
+
"notifications"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/wunankun/dsh-task-traffic-light#readme",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/wunankun/dsh-task-traffic-light.git"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/wunankun/dsh-task-traffic-light/issues"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"dsh": ">=0.2.1"
|
|
26
|
+
},
|
|
27
|
+
"exports": {
|
|
28
|
+
".": "./index.js",
|
|
29
|
+
"./client": "./client.js",
|
|
30
|
+
"./locale/*.json": "./locale/*.json",
|
|
31
|
+
"./icon": "./icon.svg"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"index.js",
|
|
35
|
+
"client.js",
|
|
36
|
+
"cordis.patch.yml",
|
|
37
|
+
"locale/*.json",
|
|
38
|
+
"icon.svg",
|
|
39
|
+
"README.md",
|
|
40
|
+
"README.zh.md",
|
|
41
|
+
"LICENSE"
|
|
42
|
+
],
|
|
43
|
+
"dsh": {
|
|
44
|
+
"bundle": {
|
|
45
|
+
"patch": "./cordis.patch.yml"
|
|
46
|
+
},
|
|
47
|
+
"client": {
|
|
48
|
+
"platform": "web",
|
|
49
|
+
"immediately": true,
|
|
50
|
+
"inject": [
|
|
51
|
+
"@deepseek-ai/dsh-client-ui-workspace",
|
|
52
|
+
"@deepseek-ai/dsh-client-ui-session"
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|